'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _database = require('../config/database');

var _database2 = _interopRequireDefault(_database);

var _moment = require('moment');

var _moment2 = _interopRequireDefault(_moment);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; } // import cache from '../cache'
// const orderKey = 'order_data'


const getTowDayUnixTime = () => {
  let numberDay = 2;
  let beginTime = (0, _moment2.default)((0, _moment2.default)().date(), 'DD').subtract(numberDay, 'days').unix();
  let endTime = (0, _moment2.default)((0, _moment2.default)().date(), 'DD').add(numberDay, 'days').unix();
  return {
    beginTime,
    endTime
  };
};
const getAllOrderInfo = (() => {
  var _ref = _asyncToGenerator(function* () {
    let orderData = null;
    // await cache.getCache(orderKey)
    // if (orderData === null) {
    let times = getTowDayUnixTime();
    let sql = `SELECT * FROM yp_apply_order
       WHERE UNIX_TIMESTAMP(times) > ${times.beginTime} AND UNIX_TIMESTAMP(times) < ${times.endTime} 
             AND order_status = 0`;
    console.log(sql);

    try {
      orderData = yield _database2.default.query(sql);
      console.log('serach date len is=>', orderData, orderData.length);
    } catch (err) {
      console.log(`search yp_apply_order ${err}`);
    }
    // await cache.setCache(orderKey, orderData)
    // }
    return orderData;
  });

  return function getAllOrderInfo() {
    return _ref.apply(this, arguments);
  };
})();
const updateOrderStatus = (() => {
  var _ref2 = _asyncToGenerator(function* (status, sdcustomno) {
    let sql = `
    UPDATE yp_apply_order
    SET order_status = ${status}
    WHERE  order_no = ${sdcustomno}
  `;
    try {
      yield _database2.default.query(sql);
      // await cache.cleanCache(orderKey)
      console.log('update yp_apply_order success');
    } catch (err) {
      console.log(`search yp_apply_order ${err}`);
    }
  });

  return function updateOrderStatus(_x, _x2) {
    return _ref2.apply(this, arguments);
  };
})();
exports.default = {
  getAllOrderInfo,
  updateOrderStatus
};